﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using UnityScriptEngine;
using ResortModule;

namespace MBBHotelReservation
{
    public partial class frmDailySalesViewer : Form
    {
        UnityProcessor proc = new UnityProcessor();
        UnityScript[] dat = new UnityScript[0];
        Threader t = new Threader();
        
        DataTable items = new DataTable();

        DataTable check = new DataTable();
        DataTable expenses = new DataTable();
        DataTable cashDenomination = new DataTable();
        DataTable dsamenities = new DataTable();
        DataTable card = new DataTable();
        DataTable cash = new DataTable();
        string cat = "";

        float cashTotal = 0f, cardTotal = 0f, expensesTotal = 0f, checkTotal = 0f, amenitiesTotal = 0f, denominationTotal = 0f;
        details[] detail = new details[0];

        public frmDailySalesViewer()
        {
            InitializeComponent();
            InitializeFrameSliderForm();
            
        }
        private void InitializeForm()
        {
            proc.ProcessCompleted += new ProcessHandler(proc_ProcessCompleted);
            proc.ProcessError += new ProcessHandler(proc_ProcessError);
            t.MethodCompleted += new EventHandler(t_MethodCompleted);
            cat = txtCategory.Text;
            //events
            btnView.Click += new EventHandler(btnView_Click);
            btnPrint.Click += new EventHandler(btnPrint_Click);

            txtCategory.SelectedIndex = 0;
        }
        void btnPrint_Click(object sender, EventArgs e)
        {
            if (grdItems.Rows.Count > 0)
            {

            }
            //for testing
            PrintDailySales();
        }
        void btnView_Click(object sender, EventArgs e)
        {
            cat = txtCategory.Text;
            grpSearchDetails.Enabled = false;
            t.MethodCall(LoadData);
        }
        
        //Process Ended
        void proc_ProcessError(string id, string desc)
        {
            t.SafeCall(this, delegate
            {
                
                MessageBox.Show(desc);
            });
        }
        void proc_ProcessCompleted(string id, string desc)
        {
            t.SafeCall(this, delegate
            {
                switch (id)
                {
                    case "LOAD":
                        proc.DBPUX_Data_Fetch(out dat);
                        check = dat[0].ToDataTable();
                        expenses = dat[1].ToDataTable();
                        cashDenomination = dat[2].ToDataTable();
                        dsamenities = dat[3].ToDataTable();
                        cash = dat[4].ToDataTable();
                        card = dat[5].ToDataTable();

                        t.MethodCall(joinTables);
                        break;
                };
                States(true);
            });
        }
        void t_MethodCompleted(object sender, EventArgs e)
        {
            t.SafeCall(this, delegate
            {
                switch (sender.ToString())
                {
                    case "joinTables": 
                        items = new DataTable();
                        items.Columns.Add("Official Receipt");
                        items.Columns.Add("Cash Amount");
                        items.Columns.Add("OR Number");
                        items.Columns.Add("Debit/Credit Card");
                        items.Columns.Add("Debit/Credit Amount");
                        items.Columns.Add("Check Number");
                        items.Columns.Add("Check Amount");
                        items.Columns.Add("Amenities");
                        items.Columns.Add("Order Slip");
                        items.Columns.Add("OS Amount");
                        items.Columns.Add("Expenses");
                        items.Columns.Add("Expenses Amount");
                        items.Columns.Add("Denomination");
                        items.Columns.Add("pcs");
                        items.Columns.Add("SubTotal");

                        for (int i = 0; i < detail.Length; i++)
                        {
                            DataRow dr = items.NewRow();
                            dr["Official Receipt"] = detail[i].cashOR;
                            dr["Cash Amount"] = detail[i].cashAmount;
                            dr["OR Number"] = detail[i].cardOR;
                            dr["Debit/Credit Card"] = detail[i].cardNum;
                            dr["Debit/Credit Amount"] = detail[i].cardAmount;
                            dr["Check Number"] = detail[i].checkNumber;
                            dr["Check Amount"] = detail[i].checkAmount;
                            dr["Amenities"] = detail[i].amenities;
                            dr["Order Slip"] = detail[i].orderSlip;
                            dr["OS Amount"] = detail[i].orderSlipAmount;
                            dr["Expenses"] = detail[i].expenses;
                            dr["Expenses Amount"] = detail[i].expensesAmount;
                            dr["Denomination"] = detail[i].denomination;
                            dr["pcs"] = detail[i].pcs;
                            dr["SubTotal"] = detail[i].subTotal;

                            items.Rows.Add(dr);

                        }
                        grdItems.DataSource = items;
                        formatGrid();
                        grpSearchDetails.Enabled = true;
                        break;    
                   
                }
            });
        }

        //Operations
        public void LoadData()
        {
            string date = txtSearchDate.Value.ToString("yyyy-MM-dd");
            while (proc.IsRunning)
            {
                System.Threading.Thread.Sleep(1);
            }
            proc.ProcStart();
            UnityScript x = new UnityScript("LOAD", 5);
            x.Script_Add(Script.DBPUX_BEGIN);
            x.Script_Add(Script.DBPUX_QUERY, "SELECT fID, fCheckNumber, fAmount, fStamp FROM tblCheck WHERE fDate = '" + date + "' AND fCategory = '"+cat+"'");
            x.Script_Add(Script.DBPUX_QUERY, "SELECT fID, fVoucher, fDescription, fAmount, fType, fStamp FROM tblExpenses WHERE fDate = '" + date + "' AND fCategory = '" + cat + "'");
            x.Script_Add(Script.DBPUX_QUERY, "SELECT fID, fDenomination, fPcs, fDenomination * fPcs, fStamp FROM tblCashRegistry WHERE fDate = '" + date + "' AND fCategory = '" + cat + "'");
            x.Script_Add(Script.DBPUX_QUERY, "SELECT fID, fOrderSlipNum, fType, fAmount, fStamp FROM tbldsamenities WHERE fDate = '" + date + "'");
            x.Script_Add(Script.DBPUX_QUERY, "SELECT fID, fOfficialReceipt, fPaymentAmount, fStamp FROM tblpayments WHERE fDate = '" + date + "' AND fType = 'Cash'");
            x.Script_Add(Script.DBPUX_QUERY, "SELECT fID, fOfficialReceipt, fAccountNum, fPaymentAmount, fStamp FROM tblpayments WHERE fDate = '" + date + "' AND fType = 'Card'");
            x.Script_Add(Script.DBPUX_COMMIT);
            proc.Run(x);
        }
        void States(bool s)
        {
            grdItems.Enabled = s;
        }
        struct details
        {
            public string cashAmount;
            public string cashOR;
            public string cardOR;
            public string cardNum;
            public string cardAmount;
            public string checkNumber;
            public string checkAmount;
            public string denomination;
            public string pcs;
            public string subTotal;
            public string expenses;
            public string expensesAmount;
            public string amenities;
            public string orderSlip;
            public string orderSlipAmount;
        }
        void joinTables()
        {
            detail = new details[0];
            int[] rowCounts = new int[6];

            rowCounts[0] = cashDenomination.Rows.Count;
            rowCounts[1] = expenses.Rows.Count;
            rowCounts[2] = check.Rows.Count;
            rowCounts[3] = dsamenities.Rows.Count;
            rowCounts[4] = cash.Rows.Count;
            rowCounts[5] = card.Rows.Count;

            int highest = rowCounts[0];
            for (int i = 0; i < rowCounts.Length; i++)
            {
                if (highest < rowCounts[i])
                {
                    highest = rowCounts[i];
                }
            }

            int j = 0;
            cashTotal = 0f;
            cardTotal = 0f;
            denominationTotal = 0f;
            expensesTotal = 0f;
            amenitiesTotal = 0f;
            checkTotal = 0f;

            while (j <= highest)
            {
                Array.Resize<details>(ref detail, detail.Length + 1);
                //cash
                if (j < cash.Rows.Count)
                {
                    detail[j].cashAmount = float.Parse(cash.Rows[j]["fPaymentAmount"].ToString()).ToString("#,#0.00");
                    detail[j].cashOR = cash.Rows[j]["fOfficialReceipt"].ToString();
                    cashTotal += float.Parse(detail[j].cashAmount);
                }
                if (j == cash.Rows.Count)
                {
                    detail[j].cashAmount = cashTotal.ToString("#,#0.00");
                    detail[j].cashOR = "Total Cash";
                }
                //card
                if (j < card.Rows.Count)
                {
                    detail[j].cardAmount = float.Parse(card.Rows[j]["fPaymentAmount"].ToString()).ToString("#,#0.00");
                    detail[j].cardNum = card.Rows[j]["fAccountNum"].ToString();
                    detail[j].cardOR = card.Rows[j]["fOfficialReceipt"].ToString();
                    cardTotal += float.Parse(detail[j].cardAmount);
                }
                if (j == card.Rows.Count)
                {
                    detail[j].cardAmount = cardTotal.ToString("#,#0.00");
                    detail[j].cardOR = "Total Cash";
                }
                //cash denomination
                if (j < cashDenomination.Rows.Count)
                {
                    detail[j].denomination = float.Parse(cashDenomination.Rows[j]["fDenomination"].ToString()).ToString("#,#0.00");
                    detail[j].pcs = cashDenomination.Rows[j]["fPcs"].ToString();
                    detail[j].subTotal = (float.Parse(detail[j].denomination) * float.Parse(detail[j].pcs)).ToString("#,#0.00");
                    denominationTotal += float.Parse(detail[j].subTotal);
                }
                if (j == cashDenomination.Rows.Count)
                {
                    detail[j].denomination = "Total Amount";
                    detail[j].subTotal = denominationTotal.ToString("#,#0.00");
                }
                //expenses
                if (j < expenses.Rows.Count)
                {
                    detail[j].expenses = expenses.Rows[j]["fVoucher"].ToString() +" - "+expenses.Rows[j]["fDescription"].ToString();
                    detail[j].expensesAmount = float.Parse(expenses.Rows[j]["fAmount"].ToString()).ToString("#,#0.00");
                    expensesTotal += float.Parse(detail[j].expensesAmount);
                }
                if (j == expenses.Rows.Count)
                {
                    detail[j].expenses = "Total Expenses";
                    detail[j].expensesAmount = expensesTotal.ToString("#,#0.00");
                }
                //amenities
                if (j < dsamenities.Rows.Count)
                {
                    detail[j].amenities = dsamenities.Rows[j]["fType"].ToString();
                    detail[j].orderSlip = dsamenities.Rows[j]["fOrderSlipNum"].ToString();
                    detail[j].orderSlipAmount = float.Parse(dsamenities.Rows[j]["fAmount"].ToString()).ToString("#,#0.00");
                    amenitiesTotal += float.Parse(detail[j].orderSlipAmount);
                }
                if (j == dsamenities.Rows.Count)
                {
                    detail[j].orderSlip = "Total Amount";
                    detail[j].orderSlipAmount = amenitiesTotal.ToString("#,#0.00");
                }
                //check
                if (j < check.Rows.Count)
                {
                    detail[j].checkNumber = check.Rows[j]["fCheckNumber"].ToString();
                    detail[j].checkAmount = float.Parse(check.Rows[j]["fAmount"].ToString()).ToString("#,#0.00");
                    checkTotal += float.Parse(detail[j].checkAmount);
                }
                if (j == check.Rows.Count)
                {
                    detail[j].checkNumber = "Total Check Amt";
                    detail[j].checkAmount = checkTotal.ToString("#,#0.00");
                }
                j++;
            }
        }
        void formatGrid()
        {
            //FORMAT
            grdItems.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdItems.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdItems.Columns[6].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdItems.Columns[9].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdItems.Columns[11].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdItems.Columns[14].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

            grdItems.Columns[0].DefaultCellStyle.BackColor = Color.Cornsilk;
            grdItems.Columns[1].DefaultCellStyle.BackColor = Color.Cornsilk;

            grdItems.Columns[2].DefaultCellStyle.BackColor = Color.LightBlue;
            grdItems.Columns[3].DefaultCellStyle.BackColor = Color.LightBlue;
            grdItems.Columns[4].DefaultCellStyle.BackColor = Color.LightBlue;

            grdItems.Columns[5].DefaultCellStyle.BackColor = Color.Cornsilk;
            grdItems.Columns[6].DefaultCellStyle.BackColor = Color.Cornsilk;

            grdItems.Columns[7].DefaultCellStyle.BackColor = Color.LightBlue;
            grdItems.Columns[8].DefaultCellStyle.BackColor = Color.LightBlue;
            grdItems.Columns[9].DefaultCellStyle.BackColor = Color.LightBlue;

            grdItems.Columns[10].DefaultCellStyle.BackColor = Color.Cornsilk;
            grdItems.Columns[11].DefaultCellStyle.BackColor = Color.Cornsilk;

            grdItems.Columns[12].DefaultCellStyle.BackColor = Color.LightBlue;
            grdItems.Columns[13].DefaultCellStyle.BackColor = Color.LightBlue;
            grdItems.Columns[14].DefaultCellStyle.BackColor = Color.LightBlue;

            for (int i = 0; i < grdItems.Columns.Count; i++)
            {
                grdItems.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }
        }

        //Printing Module
        int i = 0;
        int pp = 1;

        void PrintDailySales()
        {
            PrintDocument pd = new PrintDocument();
            pd.DocumentName = lblText.Text;
            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
            PrintDialog pdlg = new PrintDialog();
            pdlg.Document = pd;
            // Set the page orientation to landscape.
            pd.DefaultPageSettings.Landscape = true;
            pd.DefaultPageSettings.PaperSize = new PaperSize("Folio",850, 1300);
            //pd.DefaultPageSettings.PaperSize.Width = 1300;
            //pd.DefaultPageSettings.PaperSize.Height = 850;
            if (pdlg.ShowDialog() == DialogResult.OK)
            {
                PrintPreviewDialog ppdlg = new PrintPreviewDialog();
                pp = 1;
                i = 0;
                ppdlg.Document = pd;
                ppdlg.ShowDialog();
            }
            
        }
        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            float lpp = 0;
            float y = 0;
            float tm = e.MarginBounds.Top;
            float lm = e.PageBounds.Left + 50;
            float lw = e.PageBounds.Width - 50;
            float th = e.PageBounds.Height - 100;
            float bm = e.PageBounds.Bottom - 200;
            float tHt = 0;
            float ht = 0;

            Font cFont;
            StringFormat sf = new StringFormat();
            //Title
            cFont = new Font("Arial", 16f, FontStyle.Bold);
            tHt = cFont.GetHeight(e.Graphics);
            y = 50;

            e.Graphics.DrawImage(pictureBox2.Image, 440, 35);
            sf.Alignment = StringAlignment.Center;
            e.Graphics.DrawString("Malolos Resort Club Royale ", cFont, Brushes.Black, (lw + 100) / 2, y, sf);
            //SubTitle
            y += tHt;
            tHt = cFont.GetHeight(e.Graphics);
            e.Graphics.DrawString("Daily Sales", cFont, Brushes.Black, (lw + 100) / 2, y, sf);
            //SubTitle
            y += tHt;
            cFont = new Font("Arial", 12f, FontStyle.Underline);
            tHt = cFont.GetHeight(e.Graphics);
            e.Graphics.DrawString("Date: "+txtSearchDate.Text, cFont, Brushes.Black, (lw + 100) / 2, y, sf);
            //Line
            y += tHt;
            y += tHt;
            e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm, y), new PointF(lw, y));
            
            y += tHt;
            //Table Columns
            cFont = new Font("Arial", 11f, FontStyle.Bold);
            y += tHt;
            e.Graphics.DrawString("Official Receipt", cFont, Brushes.Black, new RectangleF(lm + 50,y,200,tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 200, tHt)));

            e.Graphics.DrawString("Credit Card", cFont, Brushes.Black, new RectangleF(lm + 260, y, 400, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 400, tHt)));

            e.Graphics.DrawString("Check Payment", cFont, Brushes.Black, new RectangleF(lm + 445, y, 600, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 600, tHt)));

            e.Graphics.DrawString("Amenities", cFont, Brushes.Black, new RectangleF(lm + 665, y, 800, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 800, tHt)));

            e.Graphics.DrawString("Expenses", cFont, Brushes.Black, new RectangleF(lm + 865, y, 1000, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 1000, tHt)));

            e.Graphics.DrawString("Denomination", cFont, Brushes.Black, new RectangleF(lm + 1055, y, 1200, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 1200, tHt)));

            y += tHt;
            e.Graphics.DrawString("OR", cFont, Brushes.Black, new RectangleF(lm + 34, y, 100, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 100, tHt)));
            e.Graphics.DrawString("Amount", cFont, Brushes.Black, new RectangleF(lm + 124, y, 200, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 200, tHt)));
            e.Graphics.DrawString("OR", cFont, Brushes.Black, new RectangleF(lm + 234, y, 300, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 298, tHt)));
            e.Graphics.DrawString("Amount", cFont, Brushes.Black, new RectangleF(lm + 324, y, 400, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 400, tHt)));
            e.Graphics.DrawString("Check #", cFont, Brushes.Black, new RectangleF(lm + 414, y, 300, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 496, tHt)));
            e.Graphics.DrawString("Amount", cFont, Brushes.Black, new RectangleF(lm + 522, y, 400, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 600, tHt)));
            e.Graphics.DrawString("O.S.  #", cFont, Brushes.Black, new RectangleF(lm + 614, y, 300, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 696, tHt)));
            e.Graphics.DrawString("Amount", cFont, Brushes.Black, new RectangleF(lm + 722, y, 400, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 800, tHt)));
            e.Graphics.DrawString("Details", cFont, Brushes.Black, new RectangleF(lm + 804, y, 300, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 896, tHt)));
            e.Graphics.DrawString("Amount", cFont, Brushes.Black, new RectangleF(lm + 922, y, 400, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 1000, tHt)));
            e.Graphics.DrawString("Denomination", cFont, Brushes.Black, new RectangleF(lm + 1004, y, 300, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 1104, tHt)));
            e.Graphics.DrawString("Amount", cFont, Brushes.Black, new RectangleF(lm + 1122, y, 400, tHt), new StringFormat());
            e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(new RectangleF(lm + 4, y, 1200, tHt)));
            //Table
            y += (tHt * 1.25f);
            cFont = new Font("Arial Narrow", 10f, FontStyle.Regular);
            ht = cFont.GetHeight(e.Graphics);
            tHt = ht = cFont.GetHeight(e.Graphics);
            lpp = (bm - y) / tHt;
            int cl = 0;
            
            bool nf = false;
            while (cl <= lpp && i < grdItems.Rows.Count)
            {
                if (grdItems.Rows.Count > i)
                {
                    sf.Alignment = StringAlignment.Near;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[0].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 5, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Far;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[1].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 105, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Near;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[2].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 205, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Far;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[4].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 305, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Near;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[5].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 405, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Far;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[6].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 505, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Near;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[8].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 605, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Far;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[9].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 705, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Near;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[10].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 805, y, 100, tHt), sf);
                    sf.Alignment = StringAlignment.Far;
                    e.Graphics.DrawString("" + grdItems.Rows[i].Cells[11].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 905, y, 100, tHt), sf);
                    if (!grdItems.Rows[i].Cells[12].Value.ToString().Equals(""))
                    {
                        sf.Alignment = StringAlignment.Near;
                        e.Graphics.DrawString("" + grdItems.Rows[i].Cells[12].Value.ToString() + " * " + grdItems.Rows[i].Cells[13].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 1005, y, 100, tHt), sf);
                        sf.Alignment = StringAlignment.Far;
                        e.Graphics.DrawString("" + grdItems.Rows[i].Cells[14].Value.ToString(), cFont, Brushes.Black, new RectangleF(lm + 1105, y, 100, tHt), sf);
                    }
                }
                else
                {
                    if (!nf)
                    {
                        //Nothing Follows
                        e.Graphics.DrawString("******************** Nothing Follows ********************", cFont, Brushes.Black, lm + 300, y, new StringFormat());
                        nf = true;
                    }
                }
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm+4, y + tHt), new PointF(lw+4, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm+4, y - (tHt / 2)), new PointF(lm+4, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lw+4, y - (tHt / 2)), new PointF(lw+4, y + tHt));
                //cash
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 104, y - (tHt / 2)), new PointF(lm + 104, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 204, y - (tHt / 2)), new PointF(lm + 204, y + tHt));
                //card
                //e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 269, y - (tHt / 2)), new PointF(lm + 269, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 302, y - (tHt / 2)), new PointF(lm + 302, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 404, y - (tHt / 2)), new PointF(lm + 404, y + tHt));
                //check
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 500, y - (tHt / 2)), new PointF(lm + 500, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 604, y - (tHt / 2)), new PointF(lm + 604, y + tHt));
                //amenities
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 700, y - (tHt / 2)), new PointF(lm + 700, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 804, y - (tHt / 2)), new PointF(lm + 804, y + tHt));
                //expenses
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 900, y - (tHt / 2)), new PointF(lm + 900, y + tHt));
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 1004, y - (tHt / 2)), new PointF(lm + 1004, y + tHt));
                //denomination
                e.Graphics.DrawLine(new Pen(Color.Black), new PointF(lm + 1108, y - (tHt / 2)), new PointF(lm + 1108, y + tHt));

                y += (tHt * 1.25f);

                i++;
                cl++;
            }
            if (i < grdItems.Rows.Count)
            {
                e.HasMorePages = true;
                pp++;
            }
            else
            {
                pp = 1;
                e.HasMorePages = false;
                i = 1;

                e.Graphics.DrawString("******************** Nothing Follows ********************", cFont, Brushes.Black, lm + 300, y, new StringFormat());
                y += tHt;
                e.Graphics.DrawString("****************** Tally ********************", cFont, Brushes.Black, lm + 10, y, new StringFormat());
                
                y += tHt;
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString("A. Credit Card Total Amount:", cFont, Brushes.Black, lm + 10, y, sf);
                sf.Alignment = StringAlignment.Far;
                e.Graphics.DrawString("" + cardTotal.ToString("#,#0.00"), cFont, Brushes.Black, lm + 300, y, sf);

                y += tHt;
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString("B. Check Total Amount:", cFont, Brushes.Black, lm + 10, y, sf);
                sf.Alignment = StringAlignment.Far;
                e.Graphics.DrawString("" + checkTotal.ToString("#,#0.00"), cFont, Brushes.Black, lm + 300, y, sf);

                y += tHt;
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString("C. Total Amount of Cash Denomination:", cFont, Brushes.Black, lm + 10, y, sf);
                sf.Alignment = StringAlignment.Far;
                e.Graphics.DrawString("" + denominationTotal.ToString("#,#0.00"), cFont, Brushes.Black, lm + 300, y, sf);

                y += tHt;
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString("D. Amenities Total Amount:", cFont, Brushes.Black, lm + 10, y, sf);
                sf.Alignment = StringAlignment.Far;
                e.Graphics.DrawString("" + amenitiesTotal.ToString("#,#0.00"), cFont, Brushes.Black, lm + 300, y, sf);

                y += tHt;
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString("**** Sub Total Amount:", cFont, Brushes.Black, lm + 10, y, sf);
                sf.Alignment = StringAlignment.Far;
                e.Graphics.DrawString("" + (cardTotal + checkTotal + amenitiesTotal + denominationTotal).ToString("#,#0.00"), cFont, Brushes.Black, lm + 300, y, sf);

                y += tHt;
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString("E. Total Amount of Expenses:", cFont, Brushes.Black, lm + 10, y, sf);
                sf.Alignment = StringAlignment.Far;
                e.Graphics.DrawString("" + expensesTotal.ToString("#,#0.00"), cFont, Brushes.Black, lm + 300, y, sf);

                y += tHt;
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString("**** Grand Total Amount:", cFont, Brushes.Black, lm + 10, y, sf);
                sf.Alignment = StringAlignment.Far;
                e.Graphics.DrawString("" + (cardTotal + checkTotal + amenitiesTotal + denominationTotal - expensesTotal).ToString("#,#0.00"), cFont, Brushes.Black, lm + 300, y, sf);
            }           
        }

    }
    //Code Log:
    //- Speed up entry checking by removing the method call from the timer.
    //- Removed the CheckContent method as the CheckEntry method is sufficient for checking
    //  user inputs.
}